<meta charset="UTF-8">
<div class="container">
	<form action="aaa" class="form-inline">
		<div class="form-group" style="margin-top: 20px">
			<label>选择班级：</label> <input class="form-control" name="banji"
				id="banji" type="text" />
		</div>
		<div class="form-group" style="margin-top: 20px">
			<label>选择课程：</label> <input class="form-control" name="kc" id="kc"
				type="text" />
		</div>
		<div class="form-group" style="margin-top: 20px; margin-left: 50px;">
			<button type="button" class="btn btn-default" onclick="cx()">查询</button>
		</div>
	</form>
	<div id="table"></div>
</div>
<script type="text/javascript">
	var bjId=0;
	var kcId=0;
	$(function(){
		$('#banji').combobox({
			url:'banji/list',
			valueField:'id',
			textField:'name',
			onchange:function(id){
				bjId=id;
			}
		});
		$('#kc').combobox({
			url:'course/list',
			valueField:'id',
			textField:'name',
			onchange:function(id){
				kcId=id;
			}
		});
	});
	function cx(){
		$('#table').empty();
		var table = $('<table id="mytable" />');
		table.appendTo($('#table'));
		var thead = $('<thead/>');
		thead.appendTo($(table));
		var tr = $('<tr/>'); 
		tr.appendTo($(thead));
		var th1 = $('<th data-checkbox="true"></th>');
		var th2 = $('<th data-field="id">编号</th>');
		var th3 = $('<th data-field="student.name" >姓名</th>');
		var th4 = $('<th data-field="course.name">课程</th>');
		var th5 = $('<th data-field="grade" data-formatter="setInput">成绩</th>');
		th1.appendTo($(tr));
		th2.appendTo($(tr));
		th3.appendTo($(tr));
		th4.appendTo($(tr));
		th5.appendTo($(tr));
		$('#mytable').datagrid({
			url: 'grade/page?bjId='+bjId+'&kcId='+kcId,	
			searchUrl:'',
			buttons:[],
			search: false, 
			showToggle: false,
			showColumns: false,  
		});	
	}
	function setInput(value, row, index) {

		if(row.grade==null){
		   row.grade=0;
		}
	return '<input  type="number" class="form-control" id="input" value="'+row.grade+'"   onBlur="aaa(value) "/>';
	}
		function aaa(value){
			var a = $('#mytable').bootstrapTable('getSelections');
			var stuId = a[0].id;
			 $.post('grade/save',{id:stuId,grade:value},function(data){});
		}


</script>